import request from '@/utils/request'

export function init() {
  return request({
    url: '/work/board/init',
    method: 'get'
  })
}

// 多节点分布拓扑图 ==================================================
// 圆形分区
export function group(erArr, arr, r) {
  const newArray = []
  const { length: arLen } = arr
  let cloud = {}
  arr.forEach((e, ind) => {
    // 按角度均匀分布
    let ang = 0
    if (e.belong) {
      //point角度根据已经分配好的cloud的角度决定
      cloud = erArr.find((obj) => {
        return obj.name === e.belong
      })
      //多个point，在cloud的角度上递增偏移一些角度
      let index = 0
      for (let j = 0; j < cloud.children.length; j++) {
        if (cloud.children[j].name === e.name) {
          //是第几个子节点
          index = j
          break
        }
      }
      //间隔角度
      var intervalDeg = 7
      let midIndex = cloud.children.length / 2
      //执行角度平均偏移
      ang = cloud.ang + intervalDeg * (index - midIndex)
    } else {
      //分配cloud角度，并记录下
      ang = 90 - (360 / arLen).toFixed(2) * (ind + 1)
      e.ang = ang
    }
    const x = Math.cos((ang * Math.PI) / 180).toFixed(2) * r
    const y = Math.sin((ang * Math.PI) / 180).toFixed(2) * r
    e.value = [x.toFixed(2), y.toFixed(2)]
    if (e.belong) {
      let rotate = ''
      const angle = (20 / arr.length).toFixed(2)
      if (x > 0 && y >= 0) {
        rotate = (r - angle * ind).toFixed(2)
      } else if (x <= 0 && y > 0) {
        rotate = (-r + angle * (arr.length - ind)).toFixed(2)
      } else if (x < 0 && y <= 0) {
        rotate = (r - angle * (ind - arr.length * 0.5)).toFixed(2)
      } else if (x >= 0 && y < 0) {
        rotate = (-8 + angle * (arr.length * 0.25 - ind)).toFixed(2)
      }
      e.label = {
        show: true,
        width: 200,
        color: {
          lineColor: {
            color: 'rgb(24,163,239)'
          }
        },
        rotate,
        align: x > 0 ? 'left' : 'right',
        padding: x > 0 ? [0, 0, 0, 16] : [0, 16, 0, 0]
      }
      if (e.offset) {
        e.label.offset = e.offset
      }
    }
    newArray.push(e)
  })
  return newArray
}

// 线配置
export function linesConfig(arr) {
  const [dataArr, targetCoord] = [[], [0, 0]]
  arr.forEach((el) => {
    if (!el.belong) {
      dataArr.push([
        { coord: targetCoord },
        {
          coord: el.value,
          lineStyle: el.lineStyle,
          effect: {
            symbolSize: [6, 20], // 动画的大小
            period: 3, // 时间快慢
            delay: 2, // 延时计算
            ...el.effect
          }
        }
      ])
      arr.forEach((element) => {
        if (element.belong === el.name) {
          dataArr.push([
            { coord: el.value },
            {
              coord: element.value,
              lineStyle: element.lineStyle,
              effect: {
                symbolSize: [5, 15], // 动画的大小
                period: 3, // 时间快慢
                delay: 2, // 延时计算
                ...element.effect
              }
            }
          ])
        }
      })
    }
  })
  return dataArr
}

export const WayData = [
  {
    name: '监管大屏',
    pointType: 'cloud'
  },
  {
    name: '综合业务监管',
    pointType: 'cloud'
  },
  {
    name: '传染性疾病监管',
    pointType: 'cloud'
  },
  {
    name: '公共卫生监管',
    pointType: 'cloud'
  },
  {
    name: '人口信息监管',
    pointType: 'cloud'
  },
  {
    name: '民营医院监管',
    pointType: 'cloud'
  },
  {
    name: '互联网医院监管',
    pointType: 'cloud'
  },
  {
    name: '基建设备监管',
    pointType: 'cloud'
  },
  {
    name: '数据中心',
    pointType: 'cloud'
  },
  {
    name: '平台管理',
    pointType: 'cloud'
  },
  {
    name: '平台监管大屏',
    pointType: 'point',
    belong: '监管大屏'
  },
  {
    name: '综合业务监管大屏',
    pointType: 'point',
    belong: '监管大屏'
  },
  {
    name: '民营机构监管大屏',
    pointType: 'point',
    belong: '监管大屏'
  },
  {
    name: '公共卫生监管大屏',
    pointType: 'point',
    belong: '监管大屏'
  },
  {
    name: '互联网医院监管大屏',
    pointType: 'point',
    belong: '监管大屏'
  },
  {
    name: '平台监管大屏2',
    pointType: 'point',
    belong: '综合业务监管'
  },
  {
    name: '综合业务监管大屏2',
    pointType: 'point',
    belong: '综合业务监管'
  },
  {
    name: '民营机构监管大屏2',
    pointType: 'point',
    belong: '综合业务监管'
  },
  {
    name: '公共卫生监管大屏2',
    pointType: 'point',
    belong: '综合业务监管'
  },
  {
    name: '互联网医院监管大屏2',
    pointType: 'point',
    belong: '综合业务监管'
  },
  {
    name: '平台监管大屏3',
    pointType: 'point',
    belong: '传染性疾病监管'
  },
  {
    name: '综合业务监管大屏3',
    pointType: 'point',
    belong: '传染性疾病监管'
  },
  {
    name: '民营机构监管大屏3',
    pointType: 'point',
    belong: '传染性疾病监管'
  },
  {
    name: '公共卫生监管大屏3',
    pointType: 'point',
    belong: '传染性疾病监管'
  },
  {
    name: '互联网医院监管大屏3',
    pointType: 'point',
    belong: '传染性疾病监管'
  },
  {
    name: '平台监管大屏4',
    pointType: 'point',
    belong: '公共卫生监管'
  },
  {
    name: '综合业务监管大屏4',
    pointType: 'point',
    belong: '公共卫生监管'
  },
  {
    name: '民营机构监管大屏4',
    pointType: 'point',
    belong: '公共卫生监管'
  },
  {
    name: '公共卫生监管大屏4',
    pointType: 'point',
    belong: '公共卫生监管'
  },
  {
    name: '互联网医院监管大屏4',
    pointType: 'point',
    belong: '公共卫生监管'
  },
  {
    name: '平台监管大屏5',
    pointType: 'point',
    belong: '人口信息监管'
  },
  {
    name: '综合业务监管大屏5',
    pointType: 'point',
    belong: '人口信息监管'
  },
  {
    name: '民营机构监管大屏5',
    pointType: 'point',
    belong: '人口信息监管'
  },
  {
    name: '人口信息监管大屏5',
    pointType: 'point',
    belong: '人口信息监管'
  },
  {
    name: '互联网医院监管大屏5',
    pointType: 'point',
    belong: '人口信息监管'
  },
  {
    name: '平台监管大屏6',
    pointType: 'point',
    belong: '民营医院监管'
  },
  {
    name: '综合业务监管大屏6',
    pointType: 'point',
    belong: '民营医院监管'
  },
  {
    name: '民营机构监管大屏6',
    pointType: 'point',
    belong: '民营医院监管'
  },
  {
    name: '民营医院监管大屏6',
    pointType: 'point',
    belong: '民营医院监管'
  },
  {
    name: '互联网医院监管大屏6',
    pointType: 'point',
    belong: '民营医院监管'
  },
  {
    name: '平台监管大屏7',
    pointType: 'point',
    belong: '互联网医院监管'
  },
  {
    name: '综合业务监管大屏7',
    pointType: 'point',
    belong: '互联网医院监管'
  },
  {
    name: '民营机构监管大屏7',
    pointType: 'point',
    belong: '互联网医院监管'
  },
  {
    name: '民营医院监管大屏7',
    pointType: 'point',
    belong: '互联网医院监管'
  },
  {
    name: '互联网医院监管大屏7',
    pointType: 'point',
    belong: '互联网医院监管'
  },
  {
    name: '平台监管大屏8',
    pointType: 'point',
    belong: '基建设备监管'
  },
  {
    name: '综合业务监管大屏8',
    pointType: 'point',
    belong: '基建设备监管'
  },
  {
    name: '民营机构监管大屏8',
    pointType: 'point',
    belong: '基建设备监管'
  },
  {
    name: '民营医院监管大屏8',
    pointType: 'point',
    belong: '基建设备监管'
  },
  {
    name: '互联网医院监管大屏8',
    pointType: 'point',
    belong: '基建设备监管'
  },
  {
    name: '综合数据1展示大屏9',
    pointType: 'point',
    belong: '数据中心'
  },
  {
    name: '综合数据2展示大屏9',
    pointType: 'point',
    belong: '数据中心'
  },
  {
    name: '综合数据3展示大屏9',
    pointType: 'point',
    belong: '数据中心'
  },
  {
    name: '综合数据4展示大屏9',
    pointType: 'point',
    belong: '数据中心'
  },
  {
    name: '综合数据5展示大屏9',
    pointType: 'point',
    belong: '数据中心'
  },
  {
    name: '平台监管大屏10',
    pointType: 'point',
    belong: '平台管理'
  },
  {
    name: '综合业务监管大屏10',
    pointType: 'point',
    belong: '平台管理'
  },
  {
    name: '民营机构监管大屏10',
    pointType: 'point',
    belong: '平台管理'
  },
  {
    name: '民营医院监管大屏10',
    pointType: 'point',
    belong: '平台管理'
  },
  {
    name: '互联网医院监管大屏10',
    pointType: 'point',
    belong: '平台管理'
  }
]

// 动态折线图 ==================================================
export const LineData = [
  ['2000-06-05', 116],
  ['2000-06-06', 129],
  ['2000-06-07', 135],
  ['2000-06-08', 86],
  ['2000-06-09', 73],
  ['2000-06-10', 85],
  ['2000-06-11', 73],
  ['2000-06-12', 68],
  ['2000-06-13', 92],
  ['2000-06-14', 130],
  ['2000-06-15', 245],
  ['2000-06-16', 139],
  ['2000-06-17', 115],
  ['2000-06-18', 111],
  ['2000-06-19', 309],
  ['2000-06-20', 206],
  ['2000-06-21', 137],
  ['2000-06-22', 128],
  ['2000-06-23', 85],
  ['2000-06-24', 94],
  ['2000-06-25', 71],
  ['2000-06-26', 106],
  ['2000-06-27', 84],
  ['2000-06-28', 93],
  ['2000-06-29', 85],
  ['2000-06-30', 73],
  ['2000-07-01', 83],
  ['2000-07-02', 125],
  ['2000-07-03', 107],
  ['2000-07-04', 82],
  ['2000-07-05', 44],
  ['2000-07-06', 72],
  ['2000-07-07', 106],
  ['2000-07-08', 107],
  ['2000-07-09', 66],
  ['2000-07-10', 91],
  ['2000-07-11', 92],
  ['2000-07-12', 113],
  ['2000-07-13', 107],
  ['2000-07-14', 131],
  ['2000-07-15', 111],
  ['2000-07-16', 64],
  ['2000-07-17', 69],
  ['2000-07-18', 88],
  ['2000-07-19', 77],
  ['2000-07-20', 83],
  ['2000-07-21', 111],
  ['2000-07-22', 57],
  ['2000-07-23', 55],
  ['2000-07-24', 60]
]
